package cn.iocoder.yudao.module.product.framework;

import cn.iocoder.yudao.framework.datapermission.v1.UniDataPermissionRuleCustomizer;
import cn.iocoder.yudao.module.product.category.dal.dataobject.ProductCategoryDO;
import cn.iocoder.yudao.module.product.evaluation.dal.dataobject.ProductEvaluationDO;
import cn.iocoder.yudao.module.product.history.dal.dataobject.ProductBrowseHistoryDO;
import cn.iocoder.yudao.module.product.property.dal.dataobject.ProductPropertyDO;
import cn.iocoder.yudao.module.product.property.dal.dataobject.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.sku.dal.dataobject.ProductSkuDO;
import cn.iocoder.yudao.module.product.spu.dal.dataobject.ProductSpuDO;
import cn.iocoder.yudao.module.product.statistics.dal.dataobject.ProductStatisticsDO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * permission 组件的 Configuration
 */
@Configuration(proxyBeanMethods = false)
public class ProductDataPermissionConfiguration {

    @Bean
    public UniDataPermissionRuleCustomizer productDataPermissionRuleCustomizer() {
        return rule -> {
            // shop 基于店铺的数据权限
            rule.addDataColumn(ProductCategoryDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductSpuDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductSkuDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductPropertyDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductPropertyValueDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductEvaluationDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductStatisticsDO.class, "shop_id"); // WHERE shop_id = ?
            rule.addDataColumn(ProductBrowseHistoryDO.class, "shop_id"); // WHERE shop_id = ?
        };
    }

}
